/*
 * Copyright the original author or authors.
 * 
 * Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *	  http://www.mozilla.org/MPL/MPL-1.1.html
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.milib.dbg.model.dbgservice {
	import com.googlecode.milib.dbg.MLDBG;
	import com.googlecode.milib.dbg.model.content.MLDBGContainerChildsListModel;
	import com.googlecode.milib.dbg.view.content.MLDBGBitmapDrawableView;
	import com.googlecode.milib.dbg.view.content.MLDBGValuesListView;

	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.utils.Dictionary;
	import flash.utils.getQualifiedClassName;

	/**
	 * @author Marek Brun
	 */
	public class DBGServiceForDisplayObject extends DBGServiceForClass {

		private var display:DisplayObject;
		
		public function DBGServiceForDisplayObject(access:Private, display:DisplayObject) {
			super(null, display);
			this.display=display;
			className=MLDBG.getClassNameByQualifiedClassName(getQualifiedClassName(display));
			
		}
		
		private var className:String;
		private var childsListModel:MLDBGContainerChildsListModel;

		override public function getMLDBGWindowTitle():String {
			return className+' '+display.name;
		}
		
		override public function getMLDBGWindowContents():Array {
			if(display is DisplayObjectContainer){
				return [
					createChildsListView(),
					createDisplayObjectView(),
					createMethodsView(),
					createVariablesView(),					createLogView(),					createValuesView()
				];
			}else{
				return [
					createDisplayObjectView(),
					createMethodsView(),					createVariablesView()
				];
			}
		}
		
		protected function createChildsListView():MLDBGValuesListView {
			var valuesView:MLDBGValuesListView=new MLDBGValuesListView('childs');
			if(!childsListModel){
				childsListModel=new MLDBGContainerChildsListModel(display as DisplayObjectContainer);
			}
			valuesView.setModel(childsListModel);
			return valuesView;
		}
		
		protected function createDisplayObjectView():MLDBGBitmapDrawableView {
			var valuesView:MLDBGBitmapDrawableView=new MLDBGBitmapDrawableView('bitmap');
			valuesView.setModel(display);
			return valuesView;
		}
		
		private static const servicedObjects : Dictionary = new Dictionary(true);
		
		public static function forInstance(display:DisplayObject):DBGServiceForDisplayObject {
			if(servicedObjects[display]){
				return servicedObjects[display];
			}else{
				servicedObjects[display]=new DBGServiceForDisplayObject(null, display);
				return servicedObjects[display];
			}
		}
		
	}
}
internal class Private {}